package com.atguigu.qqzone.service.impl;

import com.atguigu.qqzone.dao.UserBasicDAO;
import com.atguigu.qqzone.pojo.UserBasic;
import com.atguigu.qqzone.service.UserBasicService;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: UserBasicServiceImpl
 * @Description:
 * @Author: wty
 * @Date: 2022/12/9
 */

public class UserBasicServiceImpl implements UserBasicService {
    private UserBasicDAO userBasicDAO;

    @Override
    public UserBasic getUserBasic(String loginId, String pwd) {
        String sqlStr = "SELECT * FROM t_user_basic a WHERE a.loginId = ? AND a.pwd = ?";
        return userBasicDAO.querySingle(sqlStr, UserBasic.class, loginId, pwd);
    }

    @Override
    public List<UserBasic> getUserBasicList(UserBasic userBasic) {
        String sqlStr = "SELECT a.fid AS id FROM t_friend a WHERE a.uid = ?";
        return userBasicDAO.queryMulti(sqlStr, UserBasic.class, userBasic.getId());
    }

    @Override
    public UserBasic getUserBasicById(Integer id) {
        String sqlStr = "SELECT * FROM t_user_basic a WHERE a.id = ?";
        return userBasicDAO.querySingle(sqlStr, UserBasic.class, id);
    }

    /**
     * @param
     * @return com.atguigu.qqzone.pojo.UserBasic
     * @description 注册
     * @param: loginId
     * @param: pwd
     * @date 2022/12/9 18:22
     * @author wty
     **/
    public UserBasic login(String loginId, String pwd) {
        UserBasic userBasic = getUserBasic(loginId, pwd);
        return userBasic;
    }

    /**
     * @param
     * @return java.util.List<com.atguigu.qqzone.pojo.UserBasic>
     * @description 获取好友列表
     * @param: userBasic
     * @date 2022/12/9 18:23
     * @author wty
     **/
    public List<UserBasic> getFriendList(UserBasic userBasic) {
        List<UserBasic> userBasicList = getUserBasicList(userBasic);
        List<UserBasic> friendList = new ArrayList<>(userBasicList.size());
        for (int i = 0; i < userBasicList.size(); i++) {
            UserBasic friend = userBasicList.get(i);
            friend = getUserBasicById(friend.getId());
            friendList.add(friend);
        }
        return friendList;
    }


}
